package com.tk.array;

public class Demo02 {
    public static void main(String[] args) {
        int[] arrays = {10, 20, 30};
        printArray(arrays);
        System.out.println(); //换行
        int[] reverse = reverse(arrays);
        printArray(reverse);
    }

    //反转数组元素
    public static int[] reverse(int[] arrays) {
        int[] result = new int[arrays.length];
        //反转操作
        for (int i = 0, j = result.length - 1; i < arrays.length; i++, j--) {
            result[j] = arrays[i];
        }
        return result;
    }

    //打印数组元素
    public static void printArray(int[] arrays) {
        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i] + " ");
        }
    }
}
